# Maintainer: Bruno Pagani <archange@archlinux.org>
# Contributor: Joey Dumont <joey.dumont@gmail.com>

_pkg=h5py
_mpi=openmpi
pkgname=python-${_pkg}-${_mpi}
pkgver=3.10.0
pkgrel=2
pkgdesc="General-purpose Python bindings for the HDF5 library (${_mpi} version)"
arch=(loong64 x86_64)
url="https://www.h5py.org/"
license=(BSD)
depends=(hdf5-${_mpi} liblzf python-numpy python-mpi4py)
makedepends=(cython0 python-pkgconfig python-setuptools)
checkdepends=(inetutils python-pytest python-pytest-mpi python-pytables)
conflicts=(python-h5py)
provides=(python-h5py)
source=(https://files.pythonhosted.org/packages/source/h/${_pkg}/${_pkg}-${pkgver}.tar.gz
        remove-version-check.patch)
sha256sums=('d93adc48ceeb33347eb24a634fb787efc7ae4644e6ea4ba733d099605045c049'
            '621f108e5e95dc250047501447d0dc633fbf3f8bf19e4c4b4c4d5a286864664c')
validpgpkeys=(AC47F71DB275ECD0B3DA46E857FA4540DD4EFCF7 # Thomas A Caswell (Brookhaven National Lab) <tcaswell@bnl.gov>
              96B7334D7610EE3E68AFFE589E027116943D6A8B) # Thomas A Caswell <tcaswell@bnl.gov> (new key)
# See https://github.com/h5py/h5py/issues/1299 about lack of GPG sigs for recent releases

prepare() {
  cd ${_pkg}-${pkgver}
  # Allow our mpi4py, numpy versions
  sed -i 's/mpi4py ==/mpi4py >=/g' setup.py
  sed -i 's/numpy ==/numpy >=/g' setup.py
  # Remove RPATH
  sed -i "s/settings\\['runtime_library_dirs'\\] = settings\\['library_dirs'\\]/pass/" setup_build.py
  # Drop annoying version check
  patch -p1 -i ../remove-version-check.patch
}

build() {
  export CC=mpicc
  cd ${_pkg}-${pkgver}
  HDF5_MPI="ON" H5PY_SYSTEM_LZF=1 python setup.py build
}

check() {
  local python_version=$(python -c 'import sys; print("".join(map(str, sys.version_info[:2])))')
  export H5PY_TEST_CHECK_FILTERS=1
  PYTHONPATH="$PWD/${_pkg}-${pkgver}/build/lib.linux-$CARCH-cpython-${python_version}" python -m pytest --pyargs h5py -rxXs --color=yes --with-mpi
}

package() {
  cd ${_pkg}-${pkgver}
  HDF5_MPI="ON" python setup.py install --root="${pkgdir}" --skip-build --optimize=1
  install -Dm644 licenses/license.txt -t "${pkgdir}"/usr/share/licenses/${pkgname}/
}
